import AniBox from '../libs/AniBox.esm.js'
import { zrender } from '../libs/zrender-helper.js'
import { convertPosition } from './main.js'
import store from '../store/index.js'

export const createShoot = (player) => {
  let { main,config } = store.state;
  let shoot = new AniBox({
    data(){
      return {
        x : player.x,
        y : player.y,
        status : 1, //1显示 2隐藏
        power : config.player.shoot.power,
      }
    },
    methods : {
      destroy(){
        this.sleep();
        this.status = 2;
        main.remove(this.shape);
        this.context.removeShoot(this);
      },
      checkOutRange(){
        if(this.y > config.height){
          this.destroy();
        }
      },
    },
    step(){
      this.y += config.player.shoot.vy;
      this.checkOutRange();
    },
    created(){
      let shape = new zrender.Rect({
        shape : {
          width : 2,
          height : 2,
        },
        style : {
          fill : 'blue'
        }
      });
      main.add(shape);
      this.shape = shape;
    },
    render(){
      this.shape.attr({
        position : convertPosition([this.x,this.y])
      })
    }
  });
  return shoot;
}
